package utils;

import android.content.Context;
import android.os.Environment;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class SaveHexStringToFile {
    public static void saveHexStringToFile(Context context, String hexString) {
        FileOutputStream fos = null;
        try {
            // 指定文件名和路径
            String fileName = "save.bin";

            // 获取内部存储路径
            File file = new File(context.getFilesDir(), fileName); // 内部存储路径
//            File file = new File(Environment.getExternalStorageDirectory(), fileName);


            // 创建文件输出流
            fos = new FileOutputStream(file);

            // 将 hexString 写入文件
            fos.write(hexString.getBytes());
            fos.flush();
            System.out.println("保存成功: " + file.getAbsolutePath());
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("保存失败");
        } finally {
            // 确保文件输出流在使用完后关闭
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

